<?php

/* do_action.php
	Performs administrative actions
	** this version is designed for the GALLERY **
*/

error_reporting(0);
session_start();
error_reporting(1);

if ($_SESSION['level'] == "admin")
{

	require_once "../PinSQL.obj" ;
	$pinSQL = new PinSQL();
	
	$type = $_GET['type'];
	require_once "Gallery_new.obj";
	include "setupGallery.php"; //creates a $gallery object which we can use for table names and other specifics
	
	$itemID = $_GET["itemid"];
	
	$action = $_GET["actionname"];
	
	switch ($action)
	{
		case 'clearratings':
			mysql_query("UPDATE $gallery->dataTable SET totalstars='0', totalratings='0' WHERE id='$itemID'")
	 		or die(mysql_error());
	 		
	 		echo "All ratings cleared successfully.<br><b>Note: A refresh is strongly recommended.</b>";
			break;
			
		case 'erasecomments':
			mysql_query("DELETE FROM $gallery->commentsTable WHERE itemid='$itemID'")
			or die(mysql_error());
			
			echo "All comments erased successfully.<br><b>Note: A refresh is strongly recommended.</b>";
			break;
			
		case 'deletereference':
			mysql_query("DELETE FROM $gallery->dataTable WHERE id='$itemID'")
			or die(mysql_error());
			
			echo "Reference to this song was successfully deleted.<br><b>Note: A refresh is strongly recommended.</b>";
			break;
			
		case 'deletesong':
			$pinSQL->Query("SELECT * FROM $gallery->dataTable WHERE id='$itemID'");
			
			$row = $pinSQL->FetchNextRow();
			
			$artist = $row['artist'];
			$filename = $row['filename'];
			
			$fullPath = "../../members/userData/$artist/$gallery->containerPath/$filename";
			echo "Deleting: $fullPath ...";
			unlink($fullPath);
			echo "<br>File deleted successfully.";
			
			if ($type = "pictures")
			{
				// also delete thumbnail
				echo "Also delete thumbnail:";
				$thumbFilename = $row['thumburl'];
				$fullPath = "../../members/userData/$artist/$gallery->containerPath/$thumbFilename";
				echo "Deleting: $fullPath ...";
				unlink($fullPath);
				echo "<br>File deleted successfully.";
			}

			
			$pinSQL->Query("DELETE FROM $gallery->dataTable WHERE id='$itemID'");
			
			echo "<br>Reference deleted successfully.<br><b>Note: A refresh is strongly recommended.</b>";

		}
	
	 mysql_close();
	 
	 
} else {
	
	echo "You are not currently logged in as an administrator.";
}


?>